<%@include file="menu/util.jsp" %>
<%@page contentType="text/html; charset=iso-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <fmt:bundle basename="app">
        <head>

            <%@include file="menu/wizardTablessHeader.jsp" %>

            <script type="text/javascript">

                //validator
                $.validator.setDefaults({
                    submitHandler: function() {
                
    
                        var name = $('#name').attr('value');
                        var description = document.getElementById("description").value;
         

                        if($('#comparId').attr('value') > 0){
                            var id = $('#comparId').attr('value');
                            editComparation(id,name);
        
                        }else{

                            insertComparation(name,description);
                        }
                    }
                });

                $().ready(function() {
                    // validate the comment form when it is submitted
                    $("#newComparation").validate({
                        errorLabelContainer: $(".errorDiv"),
                        wrapper: "li"
                    });
                    $("#comparationId").change(function(){
     


                        selectComparation($(this).val());
                    });


                    $("#name").change(function(){
                        var name = document.getElementById("name");
                        var names = name.form.nameUsed;

                        for(i=0;names.length;i++)
                            if($.trim(''+names[i].value).toUpperCase() == $.trim(name.value+'').toUpperCase()){
                                name.value = "";
                                break;
                            }

                    });

                    $(".deleteMessage").colorbox({width:"50%", inline:true, href:"errorDelete"});


                });
            </script>

            <c:set var="name" value=""/>
            <c:set var="id" value="-1"/>

            <c:if test="${comparate != null}" >
                <c:set var="name" value="${comparate.name}"/>
                <c:set var="description" value="${comparate.description}"/>
                <c:set var="id" value="${comparate.idComparation}"/>
            </c:if>


        </head>

        <body style="overflow:hidden;" >
            <form id="newComparation" action="newComparation.do">

                <%@include file="menu/wizardTablessHeader2.jsp" %>
                <c:if test="${comparations != null && !empty comparations}">
                    <c:forEach var="comparationUsed" items="${comparations}">
                        <input type="hidden" name="nameUsed" value="${comparationUsed.name}" />
                    </c:forEach>
                </c:if>
                <table>
                    <tr>
                        <td>
                            <fmt:message key="forms.name" />
                        </td>
                        <td>
                            <input class="required" title="<fmt:message key="error.comparation.name"/>" type="text" name="name" id="name" value="${name}" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <fmt:message key="forms.description" />
                        </td>
                        <td>
                            <textarea style="width: 450px;" name="description" id="description">${description}</textarea>
                        </td>
                    </tr>

                    <tr>
                        <td colspan="2">
                        </td>
                    </tr>
                </table>
                <input type="hidden" id="comparId" name="Id" value="${id}" />

                <%@include file="menu/wizardTablessMidle.jsp" %>
                <%@include file="menu/wizardTablessFooter.jsp" %>
            </form>

            <div style='display:none' class="deleteMessage">
                <div id='errorDelete' style='padding:10px; background:#fff;'>
                    <p><fmt:message key="error.delete" /></p>
                </div>
            </div>

        </body>
    </fmt:bundle>
</html>












